var t = getApp();

Page({
    data: {
        titlist: [],
        catlogName: "",
        borderBotom: "",
        Cbox: "Cframe2",
        condition: !1,
        num: 100,
        msg: "——加载更多——",
        MY: "Cbutton",
        FW: "Cbutton",
        RZ: "Cbutton",
        ZL: "Cbutton",
        FC: "Cbutton",
        CY: "Cbutton",
        QS: "Cbutton",
        ZS: "Cbutton",
        QT: "Cbutton"
    },
    onLoad: function(a) {
        t.GetUrl();
        var o = t.globalData.seachlist;
        o && o.length > 0 && this.setData({
            seachlist: o,
            condition: !0
        });
        var n = t.globalData.catList;
        if (n && n.length > 0) {
            this.setData({
                titlist: n,
                Cbox: "Cframe",
                borderBotom: "————————"
            });
            var e = wx.getStorageSync("catIndex");
            "MY" == e && this.setData({
                MY: "Sbutton",
                catlogName: "贸易类合同"
            }), "FW" == e && this.setData({
                FW: "Sbutton",
                catlogName: "服务类合同"
            }), "RZ" == e && this.setData({
                RZ: "Sbutton",
                catlogName: "融资类合同"
            }), "ZL" == e && this.setData({
                ZL: "Sbutton",
                catlogName: "租赁类合同"
            }), "FC" == e && this.setData({
                FC: "Sbutton",
                catlogName: "房产建筑类"
            }), "CY" == e && this.setData({
                CY: "Sbutton",
                catlogName: "储运类合同"
            }), "QS" == e && this.setData({
                QS: "Sbutton",
                catlogName: "权属经营类"
            }), "ZS" == e && this.setData({
                ZS: "Sbutton",
                catlogName: "知识产权类"
            }), "QT" == e && this.setData({
                QT: "Sbutton",
                catlogName: "其他类合同"
            });
        }
    },
    seachSubmit: function(a) {
        var o = this, n = a.detail.value.seachKey, e = this.Delplace(n);
        (e.length <= 0 || !e) && wx.showToast({
            title: "关键词不能为空",
            icon: "loading",
            duration: 2e3
        }), e && e.length < 60 && (wx.showToast({
            title: "数据加载中",
            icon: "loading",
            duration: 2e4
        }), wx.request({
            url: t.url + "addon/Models/Models/" + t.globalData.SearchUrl,
            data: {
                title: e
            },
            method: "GET",
            header: {
                "Content-Type": "application/json",
                Cookie: "PHPSESSID=" + wx.getStorageSync("PHPSESSID")
            },
            success: function(a) {
                if (wx.hideToast(), a.data) {
                    var n = a.data.sort(function(t, a) {
                        return t.title.localeCompare(a.title);
                    });
                    o.setData({
                        seachlist: n,
                        condition: !0
                    }), t.globalData.seachlist = n;
                } else wx.showToast({
                    title: "换个关键词试试",
                    icon: "loading",
                    duration: 2e3
                }), o.setData({
                    seachlist: "",
                    condition: !1
                }), t.globalData.seachlist = "";
            },
            fail: function(t) {
                wx.hideToast(), wx.showToast({
                    title: "无法连接网络",
                    icon: "loading",
                    duration: 2e3
                });
            }
        })), t.globalData.catList = "";
    },
    packUp: function() {
        this.setData({
            seachlist: "",
            condition: !1
        }), t.globalData.seachlist = "";
    },
    back: function() {
        wx.switchTab({
            url: "../Draft/Draft"
        }), t.globalData.seachlist = "", t.globalData.catList = "";
    },
    openDetail: function(a) {
        var o = a.target.dataset.id, n = a.target.dataset.list, e = t.globalData.MdDetailUrl, l = n[o].id;
        wx.redirectTo({
            url: "../../pages/Modelht/Modelht?id=" + l + "&url=Models/Models/" + e + "&url2=Smcontract/Smcontract/newContract&From=Model"
        });
        var s = "Modelstr_" + l;
        t.globalData[s] = l, console.log(a);
    },
    openCatlog: function(a) {
        this.setData({
            Cbox: "Cframe"
        });
        var o = this, n = a.target.dataset.index, e = n + "_catlog", l = wx.getStorageSync(e);
        !l || l.length <= 0 ? (wx.showToast({
            title: "数据加载中",
            icon: "loading",
            duration: 2e4
        }), wx.request({
            url: t.url + "addon/Models/Models/openCatlog",
            data: {
                index: n
            },
            method: "GET",
            header: {
                "Content-Type": "application/json",
                Cookie: "PHPSESSID=" + wx.getStorageSync("PHPSESSID")
            },
            success: function(a) {
                var n = a.data.sort(function(t, a) {
                    return t.alpha.localeCompare(a.alpha);
                });
                o.setData({
                    titlist: n
                }), wx.hideToast(), t.globalData[e] = n, wx.setStorageSync(e, n), t.globalData.catList = n;
            },
            fail: function(t) {
                wx.hideToast();
                var a = wx.getStorageSync(e);
                a && o.setData({
                    titlist: a
                }), a || wx.showToast({
                    title: "无法连接网络",
                    icon: "loading",
                    duration: 2e3
                });
            }
        })) : (this.setData({
            titlist: l
        }), t.globalData.catList = l, (!t.globalData[e] || t.globalData[e].length < 1) && wx.request({
            url: t.url + "addon/Models/Models/openCatlog",
            data: {
                index: n
            },
            method: "GET",
            header: {
                "Content-Type": "application/json",
                Cookie: "PHPSESSID=" + wx.getStorageSync("PHPSESSID")
            },
            success: function(a) {
                var n = a.data.sort(function(t, a) {
                    return t.alpha.localeCompare(a.alpha);
                });
                o.setData({
                    titlist: n
                }), t.globalData[e] = n, wx.setStorageSync(e, n);
            }
        })), "MY" == n && this.setData({
            MY: "Sbutton",
            FW: "Cbutton",
            RZ: "Cbutton",
            ZL: "Cbutton",
            FC: "Cbutton",
            CY: "Cbutton",
            QS: "Cbutton",
            ZS: "Cbutton",
            QT: "Cbutton",
            catlogName: "贸易类合同",
            borderBotom: "————————"
        }), "FW" == n && this.setData({
            FW: "Sbutton",
            MY: "Cbutton",
            RZ: "Cbutton",
            ZL: "Cbutton",
            FC: "Cbutton",
            CY: "Cbutton",
            QS: "Cbutton",
            ZS: "Cbutton",
            QT: "Cbutton",
            catlogName: "服务类合同",
            borderBotom: "————————"
        }), "RZ" == n && this.setData({
            RZ: "Sbutton",
            MY: "Cbutton",
            FW: "Cbutton",
            ZL: "Cbutton",
            FC: "Cbutton",
            CY: "Cbutton",
            QS: "Cbutton",
            ZS: "Cbutton",
            QT: "Cbutton",
            catlogName: "融资类合同",
            borderBotom: "————————"
        }), "ZL" == n && this.setData({
            ZL: "Sbutton",
            MY: "Cbutton",
            FW: "Cbutton",
            RZ: "Cbutton",
            FC: "Cbutton",
            CY: "Cbutton",
            QS: "Cbutton",
            ZS: "Cbutton",
            QT: "Cbutton",
            catlogName: "租赁类合同",
            borderBotom: "————————"
        }), "FC" == n && this.setData({
            FC: "Sbutton",
            MY: "Cbutton",
            FW: "Cbutton",
            RZ: "Cbutton",
            ZL: "Cbutton",
            CY: "Cbutton",
            QS: "Cbutton",
            ZS: "Cbutton",
            QT: "Cbutton",
            catlogName: "房产建筑类",
            borderBotom: "————————"
        }), "CY" == n && this.setData({
            CY: "Sbutton",
            MY: "Cbutton",
            FW: "Cbutton",
            RZ: "Cbutton",
            ZL: "Cbutton",
            FC: "Cbutton",
            QS: "Cbutton",
            ZS: "Cbutton",
            QT: "Cbutton",
            catlogName: "储运类合同",
            borderBotom: "————————"
        }), "QS" == n && this.setData({
            QS: "Sbutton",
            MY: "Cbutton",
            FW: "Cbutton",
            RZ: "Cbutton",
            ZL: "Cbutton",
            FC: "Cbutton",
            CY: "Cbutton",
            ZS: "Cbutton",
            QT: "Cbutton",
            catlogName: "权属经营类",
            borderBotom: "————————"
        }), "ZS" == n && this.setData({
            ZS: "Sbutton",
            MY: "Cbutton",
            FW: "Cbutton",
            RZ: "Cbutton",
            ZL: "Cbutton",
            FC: "Cbutton",
            CY: "Cbutton",
            QS: "Cbutton",
            QT: "Cbutton",
            catlogName: "知识产权类",
            borderBotom: "————————"
        }), "QT" == n && this.setData({
            QT: "Sbutton",
            MY: "Cbutton",
            FW: "Cbutton",
            RZ: "Cbutton",
            ZL: "Cbutton",
            FC: "Cbutton",
            CY: "Cbutton",
            QS: "Cbutton",
            ZS: "Cbutton",
            catlogName: "其他类合同",
            borderBotom: "————————"
        }), wx.setStorageSync("catIndex", a.target.dataset.index), t.globalData.seachlist = "";
    },
    toDraftab: function() {
        wx.redirectTo({
            url: "../SdrafTable/SdrafTable"
        }), t.globalData.seachlist = "", t.globalData.catList = "";
    },
    toWdraft: function() {
        wx.redirectTo({
            url: "../Wdraft/Wdraft"
        }), t.globalData.seachlist = "", t.globalData.catList = "";
    },
    onShareAppMessage: function(t) {
        return "button" === t.from && console.log(t.target), {
            title: "合同范本查询",
            path: "",
            success: function(t) {},
            fail: function(t) {}
        };
    },
    Delplace: function(t) {
        return t.replace(/(^\s*)|(\s*$)/g, "");
    },
    loadall: function() {
        this.setData({
            num: 400,
            msg: ""
        });
    }
});